package com.lora.web;

import com.lora.entity.*;
import com.lora.service.FreshAirUpsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/public")
public class LoginController {
    @Autowired
    public FreshAirUpsService freshAirUpsService;

    @Autowired
    public JdbcTemplate jdbcTemplate;

    //新风机
    @ResponseBody
    @RequestMapping(value = "freshAirUps")
    public FreshAirUps  freshAirUps(){
        List<FreshAirUps> map=jdbcTemplate.query("SELECT * FROM `fresh_air_ups` ORDER BY create_time desc LIMIT 1", new BeanPropertyRowMapper(FreshAirUps.class));
        return map.get(0);
    }
    //空调1
    @ResponseBody
    @RequestMapping(value = "airConditioningUps1")
    public AirConditioningUps airConditioningUps1(){
        List<AirConditioningUps> map=jdbcTemplate.query("SELECT * FROM `air_conditioning_ups` " +
                " where equipmentid='ffffff100000f110'"+
                "ORDER BY create_time desc LIMIT 1", new BeanPropertyRowMapper(AirConditioningUps.class));
        return map.get(0);
    }
    //空调1
    @ResponseBody
    @RequestMapping(value = "airConditioningUps2")
    public AirConditioningUps airConditioningUps2(){
        List<AirConditioningUps> map=jdbcTemplate.query("SELECT * FROM `air_conditioning_ups` " +
                " where equipmentid='ffffff100000f10d'"+
                "ORDER BY create_time desc LIMIT 1", new BeanPropertyRowMapper(AirConditioningUps.class));
        return map.get(0);
    }
    //新风控制器数据(空调)
    @ResponseBody
    @RequestMapping(value = "freshAirContolAirConditioning")
    public FreshAirContolAirConditioning freshAirContolAirConditioning(){
        List<FreshAirContolAirConditioning> map=jdbcTemplate.query("SELECT * FROM `fresh_air_contol_air_conditioning` " +
                "ORDER BY create_time desc LIMIT 1", new BeanPropertyRowMapper(FreshAirContolAirConditioning.class));
        return map.get(0);
    }
    //门磁感器数据
    @ResponseBody
    @RequestMapping(value = "gateMahnetism")
    public GateMahnetism gateMahnetism(){
        List<GateMahnetism> map=jdbcTemplate.query("SELECT * FROM `gate_mahnetism` ORDER BY create_time desc LIMIT 1", new BeanPropertyRowMapper(GateMahnetism.class));
        return map.get(0);
    }
    //红外人体活动探测器
    @ResponseBody
    @RequestMapping(value = "humanActiveInfrared")
    public HumanActiveInfrared humanActiveInfrared(){
        List<HumanActiveInfrared> map=jdbcTemplate.query("SELECT * FROM `human_active_infrared` ORDER BY create_time desc LIMIT 1", new BeanPropertyRowMapper(HumanActiveInfrared.class));
        return map.get(0);
    }
    //红外感应器数据
    @ResponseBody
    @RequestMapping(value = "infraredinduction")
    public Infraredinduction infraredinduction(){
        List<Infraredinduction> map=jdbcTemplate.query("SELECT * FROM `infrared_induction` ORDER BY create_time desc LIMIT 1", new BeanPropertyRowMapper(Infraredinduction.class));
        return map.get(0);
    }
    //开关量
    @ResponseBody
    @RequestMapping(value = "switchingValue")
    public SwitchingValue switchingValue(){
        List<SwitchingValue> map=jdbcTemplate.query("SELECT * FROM `lora_switching_value` ORDER BY create_time desc LIMIT 1", new BeanPropertyRowMapper(SwitchingValue.class));
        return map.get(0);
    }
    //温湿度设备数据
    @ResponseBody
    @RequestMapping(value = "temperaturehumidity")
    public Temperaturehumidity temperaturehumidity(){
        List<Temperaturehumidity> map=jdbcTemplate.query("SELECT * FROM `temperature_humidity` ORDER BY create_time desc LIMIT 1", new BeanPropertyRowMapper(Temperaturehumidity.class));
        return map.get(0);
    }
    //电量仪
    @ResponseBody
    @RequestMapping(value = "electricityMeter")
    public ElectricityMeter electricityMeter(){
        List<ElectricityMeter> map=jdbcTemplate.query("SELECT * FROM `lora_electricity_meter` where  equipmentid='ffffff100000f109'" +
                " ORDER BY create_time desc LIMIT 1", new BeanPropertyRowMapper(ElectricityMeter.class));
        return map.get(0);
    }
    //市电电量仪
    @ResponseBody
    @RequestMapping(value = "sElectricityMeter")
    public ElectricityMeter sElectricityMeter(){
        List<ElectricityMeter> map=jdbcTemplate.query("SELECT * FROM `lora_electricity_meter` where  equipmentid='ffffff100000f109'" +
                " ORDER BY create_time desc LIMIT 1", new BeanPropertyRowMapper(ElectricityMeter.class));
        return map.get(0);
    }
    //ups
    @ResponseBody
    @RequestMapping(value = "ups")
    public Ups ups(){
        List<Ups> map=jdbcTemplate.query("SELECT * FROM `lora_ups` ORDER BY create_time desc LIMIT 1", new BeanPropertyRowMapper(Ups.class));
        return map.get(0);
    }
    //无线烟感数据
    @ResponseBody
    @RequestMapping(value = "wirelesssmokefeel")
    public Wirelesssmokefeel wirelesssmokefeel(){
        List<Wirelesssmokefeel> map=jdbcTemplate.query("SELECT * FROM `wireless_smoke_feel` ORDER BY create_time desc LIMIT 1", new BeanPropertyRowMapper(Wirelesssmokefeel.class));
        return map.get(0);
    }
}
